package com.bw.controller;

import com.bw.bean.KeyWord;
import com.bw.service.GmallService;
import com.bw.util.DateFormatUtil;
import com.bw.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gmall/api")
public class GmallController {
    @Autowired
    private GmallService gmallService;

    @GetMapping("/test")
    public String getTestData() {
        return "12345678";
    }

    @GetMapping("/gmv")
    public R<String> getGmv(@RequestParam(value = "date",defaultValue = "0") String date) {
        if ("0".equals(date)){
            date = DateFormatUtil.getNowDate();
        }
        return R.success(gmallService.getGmv(date));
    }
    /**
     * {
     *     "code":0
     *     "msg":"成功"
     *     "data:[
     *      {
     *          "kw":"和平"
     *          "kc":"15
     *      },
     *      {
     *          "kw":"JK"
     *      *    "kc":"15
     *      }
     *     ]
     * }
     */

    @GetMapping("/getKeyWord")
    public R<List<KeyWord>> getKeyWord(@RequestParam(value = "date",defaultValue = "0") String date) {
        if ("0".equals(date)){
            date = DateFormatUtil.getNowDate();
        }
        return R.success(gmallService.getKeyWord(date));
    }
}
